package com.ae.shield.common.tag;

import com.google.gson.JsonObject;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.ITag;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.Tags;

import javax.annotation.Nullable;

public class TagHelper {
    /**
     * @param object 包含流体标签的json
     * @return 从json中读取的流体标签，若未读取到则返回null
     */
    @Nullable
    public static ITag<Fluid> deserializeFluidTag(JsonObject object) {
        if (JSONUtils.hasField(object, "fluid_tag")) {
            String f = JSONUtils.getString(object, "fluid_tag");
            return FluidTags.createOptional(new ResourceLocation(f));
        } else {
            return null;
        }
    }

    public static Tags.IOptionalNamedTag<Item> itemTag(String name) {
        return ItemTags.createOptional(new ResourceLocation(name));
    }
}
